<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="f" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="s" uri="http://stripes.sourceforge.net/stripes.tld" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<f:message key="pokemon.title" var="title"/>
<s:layout-render name="/layout.jsp" nadpis="${title}">
    <s:layout-component name="telo">
        <div id="sidebar">
            <sec:authorize access="hasRole('ROLE_ADMIN')">
            <s:form beanclass="com.pokemon.web.PokemonActionBean">
                <fieldset id="field-table">
                    <legend><f:message key="pokemon.new"/></legend>
                    <%@include file="form.jsp"%>
                    <div>
                        <s:submit name="add"><f:message key="pokemon.create"/></s:submit>
                    </div>
                </fieldset>
            </s:form>
            </sec:authorize>
        </div>
        <div id="content">
            <s:useActionBean beanclass="com.pokemon.web.PokemonActionBean" var="actionBean"/>
            <h2><f:message key="pokemon.table.title"/></h2>
            <table id="data-table">
                <thead>
                    <tr>
                        <th width="20px"><f:message key="pokemon.table.id"/></th>
                        <th><f:message key="pokemon.table.name"/></th>
                        <th><f:message key="pokemon.table.nick"/></th>
                        <th width="70px"><f:message key="pokemon.table.type"/></th>
                        <th width="70px"><f:message key="pokemon.table.level"/></th>
                        <th><f:message key="pokemon.table.trainer"/></th>
                        <sec:authorize access="hasRole('ROLE_ADMIN')">
                        <th width="50px">&nbsp;</th>
                        <th width="50px">&nbsp;</th>
                        </sec:authorize>
                    </tr>
                </thead>
                <tbody>
                    <c:forEach items="${actionBean.pokemons}" var="pokemon">
                        <tr>
                            <td><c:out value="${pokemon.id}"/></td>
                            <td><c:out value="${pokemon.name}"/></td>
                            <td><c:out value="${pokemon.nickName}"/></td>
                            <td><f:message key="PokemonType.${pokemon.type}"/></td>
                            <td><c:out value="${pokemon.reachedLevel}"/></td>
                            <td><c:out value="${pokemon.trainer.firstName} ${pokemon.trainer.lastName}"/></td>
                            <sec:authorize access="hasRole('ROLE_ADMIN')">
                            <td class="right"><s:link beanclass="com.pokemon.web.PokemonActionBean" event="edit"><s:param name="pokemon.id" value="${pokemon.id}"/><f:message key="pokemon.table.row.edit"/></s:link></td>
                            <td class="right"><s:link beanclass="com.pokemon.web.PokemonActionBean" event="delete"><s:param name="pokemon.id" value="${pokemon.id}"/><f:message key="pokemon.table.row.remove"/></s:link></td>
                            </sec:authorize>
                        </tr>
                    </c:forEach>
                </tbody>
            </table>
        </div>
    </s:layout-component>
</s:layout-render>